#ifndef KAE_V1_ENCODE_DECODE_KEY_LOCAL_H
#define KAE_V1_ENCODE_DECODE_KEY_LOCAL_H

#include <hitls_build.h>

#include <bsl_types.h>
#include <bsl_asn1.h>
#include <crypt_types.h>
#include <crypt_eal_pkey.h>

#include "kaev1_rsa.h"

typedef enum {
    CRYPT_RSA_PUB_N_IDX = 0,
    CRYPT_RSA_PUB_E_IDX = 1,
} CRYPT_RSA_PUB_TEMPL_IDX;

typedef enum {
    CRYPT_RSA_PRV_VERSION_IDX = 0,
    CRYPT_RSA_PRV_N_IDX = 1,
    CRYPT_RSA_PRV_E_IDX = 2,
    CRYPT_RSA_PRV_D_IDX = 3,
    CRYPT_RSA_PRV_P_IDX = 4,
    CRYPT_RSA_PRV_Q_IDX = 5,
    CRYPT_RSA_PRV_DP_IDX = 6,
    CRYPT_RSA_PRV_DQ_IDX = 7,
    CRYPT_RSA_PRV_QINV_IDX = 8,
    CRYPT_RSA_PRV_OTHER_PRIME_IDX = 9
} CRYPT_RSA_PRV_TEMPL_IDX;

#define CRYPT_ASN1_CTX_SPECIFIC_TAG_RSAPSS_HASH    0
#define CRYPT_ASN1_CTX_SPECIFIC_TAG_RSAPSS_MASKGEN 1
#define CRYPT_ASN1_CTX_SPECIFIC_TAG_RSAPSS_SALTLEN 2
#define CRYPT_ASN1_CTX_SPECIFIC_TAG_RSAPSS_TRAILED 3

int32_t KAE_DECODE_RsaPubkeyAsn1Buff(uint8_t *buff, uint32_t buffLen, BSL_ASN1_Buffer *pubAsn1, uint32_t arrNum);

int32_t KAE_DECODE_RsaPrikeyAsn1Buff(uint8_t *buff, uint32_t buffLen, BSL_ASN1_Buffer *asn1, uint32_t asn1Num);

int32_t KAE_RSA_ParsePubkeyAsn1Buff(uint8_t *buff, uint32_t buffLen, BSL_ASN1_Buffer *param,
    KAE_RSA_Ctx **rsaPubKey, BslCid cid);

int32_t KAE_RSA_ParsePkcs8Key(uint8_t *buff, uint32_t buffLen, KAE_RSA_Ctx **rsaPriKey);

int32_t KAE_RSA_ParseSubPubkeyAsn1Buff(uint8_t *buff, uint32_t buffLen, KAE_RSA_Ctx **pubKey, bool isComplete);

int32_t KAE_RSA_ParsePrikeyAsn1Buff(uint8_t *buff, uint32_t buffLen, BSL_ASN1_Buffer *rsaPssParam,
    KAE_RSA_Ctx **rsaPriKey);
#endif